import { Camera, Node, math } from "cc";

/**
 * 游戏相机
 */
export class GameCamera {

    constructor(
        /** 相机组件 */
        public camera: Camera
    ) { }

    /** 相机焦点 */
    focus: Node;

    /**
     * 更新相机位置
     * @param dt
     */
    update(dt: number) {
        if (this.focus) {
            const { position: focusPos } = this.focus;
            const { position: camPos } = this.camera.node;
            const smooth = 10 * dt;
            this.camera.node.setPosition(
                math.lerp(camPos.x, focusPos.x, smooth),
                math.lerp(camPos.y, focusPos.y, smooth)
            );
        }
    }

}